//
//  BaseTableViewController.swift
//  HMWeibo007
//
//  Created by TTang on 15/6/28.
//  Copyright © 2015年 shanyu. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitiorLoginViewDelegate {
    
    // 用户登陆标记
    var userLogin = sharedUserAccount != nil
    //var userLogin = false
    //定义访客视图属性
    var visitiorView: VisitiorLoginView?
    
    override func loadView() {

        //判断如果用户没有登陆，那么进入访客视图。否则，直接返回主页
        userLogin ? super.loadView() : setVisitiorView()
    }
    

    private func setVisitiorView(){
        //替换根视图
        visitiorView  = VisitiorLoginView()
        view = visitiorView
        //设置代理
        visitiorView?.delegae = self
        //设置导航栏两侧按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerButtonClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClicked")
    }
    // MARK ： - 实现VisitiorLoginViewDelegate代理方法
    func registerButtonClicked() {
        print("注册")
    }
    
    func loginButtonClicked() {
        
        
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        //对于独立的视图最好使用modal方式呈现
        presentViewController(nav, animated: true, completion: nil)
    }
}
